import axios from 'axios';

// 创建新的axios实例
const ajax = axios.create({
    baseURL: '/api', // 设置默认头部地址，会默认讲该地址拼接到参数的前面
    withCredentials: true, // 处理跨域
});

const upload = axios.create({
    baseURL: '/api',
    withCredentials: true,
    headers: {
        'Content-Type': 'multipart/form-data'
    }
})

export default {
    get(url, params) {
        return ajax.get(url, {
            params
        })
    },
    post(url, data) {
        return ajax.post(url, data)
    },
    put(url, data) {
        return ajax.put(url, data)
    },
    delete(url, params) {
        return ajax.delete(url, {
            params
        })
    },
    upload(url, data) {
        return upload.post(url, data)
    }
}
